package com.aqie.easy.hash;


import java.util.HashMap;

/**
 * @Function: 575. 分糖果
 * @Author: aqie
 * @Date: 2019/6/30 10:50
 * 去掉一半 糖果的最大种类
 */
public class DistributeCandies {
    public int distributeCandies(int[] candies) {
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int candy : candies) {
            map.put(candy, map.getOrDefault(candy, 0) + 1);
        }
        if (map.size() >= candies.length / 2) return candies.length / 2;
        else {
            return map.size();
        }
    }

    public static void main(String[] args) {
        int [] candies = {1,1,2,2,3,3};
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < candies.length; i++){
            map.put(candies[i], map.getOrDefault(candies[i], 0) + 1);
        }
        System.out.println(map);
    }
}
